#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
using namespace std;

class Solution {
public:
    string mergeAlternately(string word1, string word2)
    {
        int m = word1.size();
        int n = word2.size();
        int i = 0;
        int j = 0;
        string ret;
        ret.reserve(m + n);
        while (i < m || j < n)
        {
            if (i < m)
                ret.push_back(word1[i++]);
            if (j < n)
                ret.push_back(word2[j++]);
        }
        return ret;
    }
};